<%@page import="com.metagurukul.metaspace.service.StatusCommentService"%>
<%@ page errorPage="/jsp/exceptionHandler.jsp"%>
<%
	if (session.getAttribute("user") == null)
		response.sendRedirect("../index.jsp");
%>

<%@page
	import="com.metagurukul.metaspace.models.beans.StatusUserDetail,com.metagurukul.metaspace.models.beans.CommentUserDetail"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
	prefix="html"%>
<%@ page import="java.util.*"%>
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta http-equiv="refresh" content="30" />
<title>Insert title here</title>
<script type="text/javascript" src="../resources/js/validation.js"></script>
<link rel="stylesheet" href="../resources/css/status.css" />
<link rel="stylesheet" href="../resources/css/style2.css" />
<script type="text/javascript" src="../resources/js/status.js"></script>
</head>
<body>

	<div id="main">
		<div class="statusModule">
			<html:form action="statusUpdate" method="post">
				<textarea name="status" rows="4"
					style="width: 100%; color: #D0CFCF;" style="resize:none;"
					onblur="FuncWaterMark(this, event);"
					onfocus="FuncWaterMark(this, event);">What's on your mind ?</textarea>
				<br />
				<div style="text-align: right;">
					<input type="button" value="Update Status" class="btn btn-inverse"
						style="margin-top: 5px" onclick="javascript: checkStatusLimit()">
				</div>
			</html:form>
		</div>

		<%
			int userId = -1;
			if (request.getSession().getAttribute("id") != null)
				userId = (Integer) request.getSession().getAttribute("id");
		%>

		<html:form action="statusDelete" method="post">
			<html:hidden property="statusId" value="" name="statusId" />
			<html:hidden property="comment" value="" name="comment" />
			<html:hidden property="commentId" value="" name="commentId" />

			<%
				ArrayList<StatusUserDetail> statusList = (ArrayList<StatusUserDetail>) StatusCommentService.getStatusList();
							for (int i = 0; i < statusList.size(); i++) {
								StatusUserDetail status = statusList.get(i);
			%>
			<div class="statusModule">
				<div class="statusPicPart">
					<%
						String profilePicForStatus;
											if (status.getProfilePicName() != null) {
												profilePicForStatus = status.getProfilePicName();
											} else {
												profilePicForStatus = "0male.jpg";
											}
					%>
					<a href="profile1.jsp?id=<%=status.getUserId()%>"><img
						src="../resources/images/users/<%=profilePicForStatus%>"
						width="50px" height="50px" alt="<%=status.getName()%>" />
					</a>
				</div>
				<div class="statusTextPart">
					<div class="statusUserName">
						<a href="profile1.jsp?id=<%=status.getUserId()%>">
							<%
								out.write(status.getName());
							%>
						</a>
					</div>
					<div class="status">
						<%
							String statusDesc = status.getStatus();
													String[] s = statusDesc.split(" ");
													for (int j = 0; j < s.length; j++) {
														while (s[j].length() > 50) {
															out.println(s[j].substring(0, 50));
															s[j] = s[j].substring(51, s[j].length());
														}
														out.println(s[j]);

													}
													//out.write(status.getStatus());
						%>
					</div>
					<div class="statusDesc">
						<span class="time">
							<%
								out.write(status.getStatusTimestamp().toLocaleString());
							%>
						</span> <span class="delete">
							<%
								if (status.getUserId() == userId) {
							%> <!-- <input type="button" value="delete"
								onclick="javascript: setUserId(<%//=status.getStatusId()%>)">-->
							<a href="#"><span class="commentButton"
								onclick="javascript: setUserId(<%=status.getStatusId()%>)">delete</span>
						</a> <%
 	}
 %> </span>
					</div>


					<hr / width=99% class="line">
					<%
						ArrayList<CommentUserDetail> commentList = (ArrayList<CommentUserDetail>) StatusCommentService
													.getCommentList(status.getStatusId());
											for (int j = 0; j < commentList.size(); j++) {
												CommentUserDetail comment = commentList.get(j);
					%>

					<div class="commentShowPart">
						<div class="commentPicPart">
							<%
								String profilePicForComment;
											if (comment.getProfilePicName() != null) {
												profilePicForComment = comment.getProfilePicName();
											} else {
												profilePicForComment = "0male.jpg";
											}
							%>
							<a href="profile1.jsp?id=<%=comment.getUserId()%>"><img
								src="../resources/images/users/<%=profilePicForComment%>"
								width="40px" height="40px" alt="<%=status.getName()%>" />
							</a>
						</div>
						<div class="commentTextPart">
							<span class="commentUserName"> <a
								href="profile1.jsp?id=<%=comment.getUserId()%>">
									<%
										out.write(comment.getName());
									%>
							</a> </span> <span class="comment"> <%
 	String commentDesc = comment.getComment();
 				String[] str = commentDesc.split(" ");
 				for (int k = 0; k < str.length; k++) {
 					while (str[k].length() > 50) {
 						out.println(str[k].substring(0, 50));
 						str[k] = str[k].substring(51, str[k].length());
 					}
 					out.println(str[k]);

 				}
 %> </span>
							<div class="commentDesc">
								<span class="time">
									<%
										out.write(comment.getCommentTimestamp()
															.toLocaleString());
									%> </span> <span class="delete"> <%
 	if ((comment.getUserId() == userId)
 						|| (userId == status.getUserId())) {
 %> <a href="#"><span class="commentButton"
										onclick="javascript: setCommentId(<%=comment.getCommentId()%>)">delete</span>
								</a> <%
 	}
 %> </span>
							</div>
						</div>
					</div>

					<hr / width=99% class="line">
					<%
						}
					%>


					<div class="commentWrite">
						<textarea name="comment<%=i%>" rows="2"
							style="width: 387px; resize: none; color: #D0CFCF;"
							onblur="FuncWaterMark(this, event);"
							onfocus="FuncWaterMark(this, event);">Comment Here....</textarea>
					</div>
					<div class="comment_Button">
						<a href="#"><span class="commentButton"
							onclick="javascript: setComment(<%=status.getStatusId()%>,'comment'+<%=i%>)">comment</span>
						</a>

					</div>
				</div>
			</div>
			<br />
			<br />
			<br />
			<br />
			<br />
			<br />
			<%
				}
			%>
		</html:form>
	</div>
</body>
</html>